﻿namespace Pract220929
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //获取汉诺塔的层数
            Console.WriteLine("请输入汉诺塔的层数：");
            int n = Convert.ToInt32(Console.ReadLine());
            processOfHanoi(n, "towerA", "towerB", "towerC");
        }
        static void processOfHanoi(int n, string towerA, string towerB, string towerC)
        {
            //把除第n层以外的n-1层看作一个整体
            if (n!=1)
            {
                //将n-1个盘经towerC移动到towerB
                processOfHanoi(n - 1, towerA, towerC, towerB);
                //将最后一个盘移动到towerC
                Console.WriteLine($"将编号为{n}的盘子从{towerA}移动到{towerC}.");
                //将n-1个盘经towerA移动到towerC
                processOfHanoi(n - 1, towerB, towerA, towerC);
            }
            //n等于1时
            else
            {
                Console.WriteLine($"将编号为{n}的盘子从{towerA}移动到{towerC}.");
            }
        }

    }
}